<?php $this->meta()->setTitle($this->pageTitle); ?>
<?php echo $this->title($this->pageTitle); ?>

<?php if (!count($this->tagItems)):?>
    <p class="empty-query">
        <?php echo $this->translate('tag')->__('There are no products matching your request'); ?>
    </p>
<?php else: ?>
<table class="product-listing-table" id="product-tags">
<?php
$i = 0;
$columnCount = 3;
foreach ($this->tagItems as $item) :
    $product = $this->products[$item['product_id']];
    $productUrl = $this->hurl(array(
            'product' => array('value' => $item['product_id'], 'seo' => $product['key_word']),
            'controller' => 'catalog',
            'action' => 'product'
       ), false, true);
?>
    <?php if ($i%$columnCount==0): ?>
        <tr>
    <?php endif; ?>

        <td>
            <div class="product-item">
                <?php if ($this->showRemove): ?>
                    <a href="<?php echo $this->href('account/tag/remove-item/itemId/' . $item['id'] . '/tagId/' . $item['customer_tag_id'], true) ?>"
                        class="tag-remove"><?php echo $this->translate('tag')->__('Remove tag from this product') ?>
                    </a>
                <?php endif; ?>
                <?php
                $imagePath = isset($product['images'][$product['image_listing']]) ?
                    $product['images'][$product['image_listing']]['path'] : '';
                $imageTitle = isset($product['images'][$product['image_listing']]) ?
                    $product['images'][$product['image_listing']]['title'] : '';
                ?>
                <a href="<?php echo $productUrl;?>" class="product-image"
                    title="<?php echo $this->escape($imageTitle) ?>"
                ><?php echo $this->imager('/product' . $imagePath, array(
                    'width'  => $this->config()->image->product->widthSmall,
                    'height' => $this->config()->image->product->heightSmall,
                    'alt' => $this->escape($imageTitle),
                    'seo' => $product['image_seo_name']
                ));
                ?></a>
                <h4 class="product-name"><a href="<?php echo $productUrl;?>"
                    title="<?php echo $this->escape($product['name']);?>"
                    ><?php echo $this->escape($product['name']);?></a></h4>
                <?php echo $this->price($product['price'],
                    !empty($product['price_discount']) ?
                        $product['price_discount'] : false
                ) ?>

                <?php if ($product['is_saleable']): ?>
                    <?php echo $this->button($this->translate('catalog')->__('Add to cart'), array(
                        'class' => 'button btn-add-to-cart',
                        'rel' => 'nofollow',
                        'href' => $this->href('checkout/cart/add/productId/' . $item['product_id'], true)
                    )) ?>
                <?php else: ?>
                    <div class="out-of-stock"><?php echo $this->translate('catalog')->__('Out of stock') ?></div>
                <?php endif ?>

                <p class="add-to">
                    <a href="<?php echo $this->href('/account/wishlist/add/id/' . $item['product_id'], true)?>"
                        rel="nofollow"
                        class="add-to-wishlist">
                        <span><span>
                            <?php echo $this->translate('catalog')->__('Add to Wishlist')?>
                        </span></span>
                    </a>
                    <br/>
                    <a href="<?php echo $this->href($this->catalogUrl . '/product-compare/add/product/') . $item['product_id'] ?>"
                        rel="nofollow"
                        class="add-to-compare">
                        <span><span>
                            <?php echo $this->translate('catalog')->__('Add to Сompare')?>
                        </span></span>
                    </a>
                </p>
            </div>
        </td>

    <?php $i++;

    if ($i%$columnCount==0) : ?>
       </tr>
    <?php endif;

endforeach;

if ($i % $columnCount != 0) :
    for($i; $i % $columnCount; $i++): ?>
        <td>&nbsp;</td>
    <?php
    endfor;?>
    </tr>
<?php endif; ?>

</table>

<script type="text/javascript">
    decorateTable('product-tags');
</script>

<?php endif ?>